<template>
    <div id="content">
        <div class="page-header">
            <div class="container-fluid">
                <div class="pull-right">
                    <a v-on:click="do_edit()" id="button-save" form="form-setting" data-toggle="tooltip" title="" class="btn btn-primary" data-original-title="保存"><i class="fa fa-save"></i></a>
                    <a href="#" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="取消"><i class="fa fa-reply"></i></a></div>
                <h1>系统设置</h1>
                <ul class="breadcrumb">
                    <li><a href="#">首页</a></li>
                    <li><a href="#">商店</a></li>
                    <li><a href="#">系统设置</a></li>
                </ul>
            </div>
        </div>
        <div class="container-fluid">         <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title"><i class="fa fa-pencil"></i> 编辑系统设置</h3>
            </div>
            <div class="panel-body">
                <form action="http://kkc.cloud.com/admin/index.php?route=setting/setting&amp;user_token=09493e256db937b3aed9e251e5e6d4ed" method="post" enctype="multipart/form-data" id="form-setting" class="form-horizontal">
                    <ul class="nav nav-tabs">
                        <!--<li class=""><a href="#tab-general" data-toggle="tab" aria-expanded="false">基本信息</a></li>-->
                        <!--<li class=""><a href="#tab-store" data-toggle="tab" aria-expanded="false">商店设置</a></li>-->
                        <!--<li class=""><a href="#tab-local" data-toggle="tab" aria-expanded="false">本地化设置</a></li>-->
                        <li class="active"><a href="#tab-option" data-toggle="tab" aria-expanded="true">选项设置</a></li>
                        <!--<li class=""><a href="#tab-image" data-toggle="tab" aria-expanded="false">图片</a></li>-->
                        <!--<li><a href="#tab-mail" data-toggle="tab">邮件协议</a></li>-->
                        <!--<li><a href="#tab-server" data-toggle="tab">服务器设置</a></li>-->
                    </ul>
                    <div class="tab-content">
                        <div class="tab-pane active" id="tab-option">

                            <fieldset>
                                <legend>账户</legend>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="input-customer-group">
                                        <span data-toggle="tooltip" title="" data-original-title="默认客户组。">默认客户组</span></label>
                                    <div class="col-sm-10">
                                        <select v-model="settings.config.customer_group_id" id="input-customer-group" class="form-control">
                                            <option v-bind:value="item.id" v-for="item in group_list">{{item.name}}</option>
                                        </select>
                                    </div>
                                </div>
                            </fieldset>
                        </div>
                    </div>
                </form>
            </div>
        </div>
        </div>
    </div>
</template>

<script>
    export default {

        data:function(){

            return {
                group_list:[],
                // config:{
                //     customer_group_id:0
                // },
                settings:{
                    config:{
                        // key:'customer_group_id',
                        // value:0,
                        // serialized:0
                        customer_group_id   : 0,
                    }
                }
            }
        },
        methods:{

            get_settings:function(){

                var url = this.config.web_url + '/admin.php?r=system/setting';
                var t = this;

                this.axios.get( url ).then(function( res ){
                    var list = res.data;
                    for( var i = 0; i < list.length; i ++ ){
                        t.settings[list[i].code][list[i].key] = list[i].value;
                    }
                });

            },

            get_customer_groups:function(){

                var url = this.config.web_url + '/admin.php?r=customer/customer_group';
                var t = this;

                this.axios.get( url ).then(function( res ){
                    t.group_list = res.data;
                });

            },

            do_edit:function(){

                var url = this.config.web_url + '/admin.php?r=system/setting/edit';
                var t = this;

                var data = "";

                var index = 0;
                for(var p in this.settings ){
                    var code = this.settings[p];

                    for(var q in code ){
                        data += "&settings[" + index + "][code]="  + p;
                        data += "&settings[" + index + "][key]="   + q;
                        data += "&settings[" + index + "][value]=" + code[q];

                        // data += "&settings[" + i + "][serialized]=0";

                        index ++;
                    }
                }


                this.axios.post( url, data ).then(function( res ){

                    t.init();
                });

            },


            init:function(){

                this.get_settings();
                this.get_customer_groups();
            }
        },

        created:function(){

            this.init();
        }


    }
</script>

<style scoped>

</style>